//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.uiotsoft.small.app.sampler.http;

import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;

import java.util.Iterator;

public class HttpGetSampler extends AbstractJavaSamplerClient {
    private String method;
    private String token;
    private String data;
    private AppHttpSampler httpSampler;

    public HttpGetSampler() {
    }

    public Arguments getDefaultParameters() {
        Arguments params = new Arguments();
        params.addArgument("gateway", "https://${gateway}/gateway");
        params.addArgument("appKey", "${appKey}");
        params.addArgument("appSecret", "${appSecret}");
        params.addArgument("method", "");
        params.addArgument("token", "");
        params.addArgument("data", "");
        return params;
    }

    private void setupValues(JavaSamplerContext context) {
        this.method = context.getParameter("method");
        this.token = context.getParameter("token");
        this.data = context.getParameter("data");
    }

    public void setupTest(JavaSamplerContext context) {
        String appKey = context.getParameter("appKey");
        String appSecret = context.getParameter("appSecret");
        String gateway = context.getParameter("gateway");
        this.httpSampler = AppHttpSampler.getInstance(appKey, appSecret, gateway);
    }

    public SampleResult runTest(JavaSamplerContext context) {
        this.setupValues(context);
        SampleResult results = new SampleResult();
        results.setDataEncoding("UTF-8");

        try {
            results.sampleStart();
            String result;
            if (this.token != null && this.token != "") {
                result = this.httpSampler.appRequestGet(this.method, this.data, this.token);
            } else {
                result = this.httpSampler.appRequestGet(this.method, this.data, (String)null);
            }

            results.setResponseData(result, (String)null);
            results.setSuccessful(true);
        } catch (Exception var7) {
            results.setSuccessful(false);
            var7.printStackTrace();
        } finally {
            results.sampleEnd();
        }

        return results;
    }

    public void teardownTest(JavaSamplerContext context) {
        super.teardownTest(context);
    }
}
